/**
 * 作为日期的筛选器，使得日期呈现YYYY-MM-DD的状态
 * **/
export function dateFormYMD(date) {
  const currentDate = new Date(date);
  const year = currentDate.getFullYear();
  let month = currentDate.getMonth() + 1;
  let day = currentDate.getDate();
  if (month < 10) {
    month = '0' + month
  }
  if (day < 10) {
    day = '0' + day
  }
  return year + '-' + month + '-' + day
}
/**
 * 作为日期的筛选器，使得日期呈现YYYY-MM-DD-HHMM的状态
 * **/
export function dateFormYMDHM(date) {
  const currentDate = new Date(date);
  const year = currentDate.getFullYear();
  let month = currentDate.getMonth() + 1;
  let day = currentDate.getDate();
  let hour = currentDate.getHours()
  let minutes = currentDate.getMinutes()
  if (month < 10) {
    month = '0' + month
  }
  if (day < 10) {
    day = '0' + day
  }
  if (hour < 10) {
    hour = '0' + hour
  }
  if (minutes < 10) {
    minutes = '0' + minutes
  }
  return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes
}

/**
 * 将年月日转换成标准时间
 */
export function formatDate(start,end){
  let date = []
  date.push(new Date(start))
  date.push(new Date(end))
  return date
}
export function getDaysBetweenDates(date1, date2) {
  const d1 = new Date(date1);
  const d2 = new Date(date2);
  d1.setHours(0, 0, 0, 0);
  d2.setHours(0, 0, 0, 0);
  const diffTime = d2.getTime() - d1.getTime();
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); // 使用Math.ceil()向上取整得到天数
  return diffDays;
}
